package net.zdreamer.shunyi.ui.myinfo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import net.zdreamer.shunyi.R;
import net.zdreamer.shunyi.adapter.CommentAdapter;
import net.zdreamer.shunyi.adapter.PhotoListAdapter;
import net.zdreamer.shunyi.myview.HorizontalListView;
import net.zdreamer.shunyi.myview.XListView;
import net.zdreamer.shunyi.utils.ImageUtil;
import net.zdreamer.shunyi.utils.ListUtils.CommentInfos;
import net.zdreamer.shunyi.utils.ListUtils.PhotolistInfos;


public class XiangQingAcitivity extends Activity implements XListView.IXListViewListener {
    private ImageView leftimg, rightimg, head_photo;
    private RelativeLayout title;
    private TextView titlecontent;
    private HorizontalListView photolist;
    private PhotoListAdapter mAdapter;
    private XListView commentlist;
    private Handler mHandler;
    private int start = 0;
    private static int refreshCnt = 0;
    private CommentAdapter commentAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiang_qing_acitivity);
        leftimg = (ImageView) findViewById(R.id.leftimg);
        rightimg = (ImageView) findViewById(R.id.right_image);
        title = (RelativeLayout) findViewById(R.id.title_item);
        titlecontent = (TextView) findViewById(R.id.title_content);
        title.setBackgroundResource(R.drawable.banghuibiaoti);
        titlecontent.setText("详情");
        titlecontent.setTextColor(getResources().getColor(R.color.gray));
        init();

        mHandler = new Handler();
    }

    private void init() {


        commentlist = (XListView) findViewById(R.id.commentlist);
        commentlist.addHeaderView(inithead());
        commentlist.setXListViewListener(this);
        commentlist.setPullLoadEnable(true);
        CommentInfos commentInfos = new CommentInfos();
        commentAdapter = new CommentAdapter(this, commentInfos.comment, R.layout.comment_item);
        commentlist.setAdapter(commentAdapter);
    }

    public View inithead() {
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.xiangqing_head, null);
        head_photo = (ImageView) view.findViewById(R.id.xiangqingphoto);

        head_photo.setImageBitmap(ImageUtil.toRoundBitmap(this, R.drawable.guangchangphoto));
        photolist = (HorizontalListView) view.findViewById(R.id.xqphotolist);
        PhotolistInfos photolistInfos = new PhotolistInfos();
        mAdapter = new PhotoListAdapter(this, photolistInfos.imagelist, R.layout.photolistitem);
        photolist.setAdapter(mAdapter);
        return view;
    }

    private void onLoad() {
        commentlist.stopRefresh();
        commentlist.stopLoadMore();
        commentlist.setRefreshTime("刚刚");
    }

    @Override
    public void onRefresh() {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                start = ++refreshCnt;
                onLoad();
            }
        }, 2000);
    }

    @Override
    public void onLoadMore() {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                onLoad();
            }
        }, 2000);
    }

}
